#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

import json
from enum import Enum


class NDMPCode(Enum):
    """
    返回给框架的code
    """
    SUCCESS = 0
    FAILED = 200


class ErrorCode(int, Enum):
    # 增量转全量
    ERROR_INCREMENT_TO_FULL = 1577209901
    # 前置任务失败


class SubJobType(int, Enum):
    PRE_SUB_JOB = 0
    GENERATE_SUB_JOB = 1
    BUSINESS_SUB_JOB = 2
    POST_SUB_JOB = 3


class BackupType(str, Enum):
    # 备份类型
    FULL_BACKUP = "1"
    DIFFERENTIAL_INCREMENTAL_BACKUP = "2"
    CUMULATIVE_INCREMENTAL_BACKUP = "3"
    PERMANENT_INCREMENTAL_BACKUP = "6"


class LogLevel(int, Enum):
    INFO = 1
    WARN = 2
    ERROR = 3
    SERIOUS = 4


class CopyFormat(int, Enum):
    SNAPSHOT = 0
    DIRECTORY = 1


class NdmpRestoreType(str, Enum):
    FULL_LEVEL = "0"
    FILE_LEVEL = "1"


class NdmpCopyStatus(int, Enum):
    INIT = 1
    PROCESSING = 2
    ABORT = 3
    FINISH = 4
    HALTED = 5
    COMPLETE = 6
    INTERNAL_ERROR = -1
    SRC_AUTH_FAILED = -2
    DST_AUTH_FAILED = -3
    DATA_CONNECT_FAILED = -4
    SEND_DST_RESTORE_FAILED = -5
    SEND_SRC_BACKUP_FAILED = -6


class NdmpFileSystemPrefix:
    DEFAULT_FILESYSTEM_PRE = "/System_vStore"


class NdmpFileAttrIndex:
    INDEX_FH = 0
    INDEX_TYPE = 1
    INDEX_MTIME = 2
    INDEX_SIZE = 3


class Constant:
    TASK_STATUS_FILE = "ndmp_task_data"
    REPORT_JOB_DETAILS = "ReportJobDetails"
    REPORT_COPY_ADDITIONAL_INFO = "ReportCopyAdditionalInfo"
    RESTORE_STATUS_FILE = "ndmp_restore_status"
    MEMORY_TRANSFORMATION_SIZE = 1024
    UTF_8 = "utf-8"
    CFG_FILE_PATH = "/opt/DataBackup/ProtectClient/ProtectClient-E/conf/testcfg.tmp"
    TIMOUT = 10 # 超时时间10s
    MAX_RETRY_TIMES = 3


class NdmpLabel:
    # 开始执行备份子任务（{0}）。
    START_BACKUP_LABEL = "plugin_start_backup_copy_subjob_label"
    # 备份子任务（{0}）正在执行中，已备份数据量：{1}。
    EXECUTE_BACKUP_LABEL = "ndmp_plugin_execute_backup_subjob_label"
    # 子任务（{0}）备份成功，共备份文件数量：{1}，共备份数据量：{2}。
    PLUGIN_BACKUP_SUBJOB_SUCCESS_LABEL = "plugin_backup_subjob_success_label"
    # 数据备份完成，共备份文件数量：{0}，共备份数据量：{1}。
    EXECUTE_BACKUP_SUCCESS_LABEL = "ndmp_plugin_backup_success_label"
    # 子任务（{0}）备份失败。
    EXECUTE_BACKUP_FAILED_LABEL = "plugin_backup_subjob_fail_label"
    # 开始执行恢复子任务（{0}）。
    START_RESTORE_LABEL = "plugin_start_restore_copy_subjob_label"
    # 恢复子任务（{0}）正在执行中，已恢复数据量：{1}。
    EXECUTE_RESTORE_LABEL = "ndmp_plugin_execute_restore_subjob_label"
    # 数据恢复完成，共恢复数据量：{0}。
    EXECUTE_RESTORE_SUCCESS_LABEL = "ndmp_plugin_restore_success_label"
    # "子任务（{0}）执行成功。"
    PLUGIN_RESTORE_SUBJOB_SUCCESS_LABEL = "plugin_task_subjob_success_label"
    # 子任务（{0}）恢复失败。
    EXECUTE_RESTORE_FAILED_LABEL = "plugin_restore_subjob_fail_label"
    # NDMP用户（{0}）鉴权失败。
    NDMP_AUTHENTICATION_FAILED_LABEL = "ndmp_authentication_failed_label"
    # 建立NDMP数据传输连接失败。
    NDMP_CREATE_DATA_CONNECT_FAILED_LABEL = "ndmp_create_data_connect_failed_label"
    # 向目的端发送请求失败。
    NDMP_SEND_RECOVER_TO_DST_FAILED_LABEL = "ndmp_send_recover_to_dst_failed_label"
    # 向源端发送请求失败。
    NDMP_SEND_BACKUP_TO_SRC_FAILED_LABEL = "ndmp_send_backup_to_src_failed_label"
    # 备份异常日志
    NDMP_PLUGIN_BACKUP_PROCESS_MSG_LABEL = "ndmp_plugin_backup_process_msg_label"
    # 恢复异常日志
    NDMP_PLUGIN_RESTORE_PROCESS_MSG_LABEL = "ndmp_plugin_restore_process_msg_label"
